home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 May / macformat-050.iso / Shareware Plus / Developers / Find_icon folder / Sources / Get_volume_icon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-25  |  2.9 KB  |  105 lines  |  [TEXT/CWIE]

  1. /*    ---------------------------------------------------------------------------------------------
  2.     Find_icon, code for constructing icon suites for files and folders
  3.     
  4.     by James W. Walker
  5.     preferred e-mail: <mailto:jwwalker@kagi.com>
  6.     alternate e-mail: <mailto:jwwalker@aol.com>, <jim@nisus-soft.com>
  7.     web: <http://users.aol.com/jwwalker/>
  8.     
  9.     File: Get_volume_icon.c
  10.     
  11.     Copyright ©1997 by James W. Walker
  12.     
  13.     You may incorporate this sample code into your applications without
  14.     restriction, though the sample code has been provided "AS IS" and the
  15.     responsibility for its operation is 100% yours.
  16.     If you're going to re-distribute the source, please make it clear
  17.     that the code was descended from James W. Walker's code,
  18.     but that you've made changes.
  19.     ---------------------------------------------------------------------------------------------
  20. */
  21.  
  22. #include <Icons.h>
  23. #ifndef __FILES__
  24.     #include <Files.h>
  25. #endif
  26. #ifndef __DEVICES__
  27.     #include <Devices.h>
  28. #endif
  29. #ifndef __RESOURCES__
  30.     #include <Resources.h>
  31. #endif
  32. #include "Get_volume_icon.h"
  33. #include "cheap-exceptions.h"
  34. #include "Get_resource_icons.h"
  35. #include "Copy_each_icon.h"
  36.  
  37. /*    ------------------------------------------------------------------
  38.     Get_volume_icon                Create an icon suite for a volume,
  39.                                 assuming that it does not have a custom
  40.                                 icon.
  41.     ------------------------------------------------------------------
  42. */
  43. OSErr    Get_volume_icon(
  44. /* --> */    short    vRefNum,
  45. /* <-- */    Handle    *the_suite
  46. )
  47. {
  48.     OSErr    err;
  49.     HParamBlockRec    pb;
  50.     ParamBlockRec    cpb;
  51.     Handle            iconHandle;
  52.     short            save_resfile;
  53.     Ptr                *drive_icon;
  54.     
  55.     pb.volumeParam.ioNamePtr = NULL;
  56.     pb.volumeParam.ioVRefNum = vRefNum;
  57.     pb.volumeParam.ioVolIndex = 0;
  58.     
  59.     err = PBHGetVInfoSync(&pb);
  60.     forbid( err, PBHGetVInfoSync );
  61.     
  62.     // set up for Control call
  63.     cpb.cntrlParam.ioCRefNum = pb.volumeParam.ioVDRefNum;
  64.     cpb.cntrlParam.ioVRefNum = pb.volumeParam.ioVDrvInfo;
  65.     drive_icon = (Ptr *) &cpb.cntrlParam.csParam;
  66.     *drive_icon = NULL;
  67.     
  68.     // Warning: Under A/UX 3.0, the csCode = 22 call can fail
  69.     // without returning an error code.
  70.     // try media icon
  71.     cpb.cntrlParam.csCode = 22;
  72.     err = PBControlSync( &cpb );
  73.  
  74.     if ( (err != noErr) || ((long)*drive_icon <= 0) )
  75.     {
  76.         // try physical drive icon;
  77.         cpb.cntrlParam.csCode = 21;
  78.         err = PBControlSync( &cpb );
  79.     }
  80.     
  81.     if ( (err == noErr) && (0 < (long)*drive_icon) )    // we got an icon
  82.     {
  83.         err = NewIconSuite( the_suite );    // create the new suite
  84.         forbid( err, NewIconSuite );
  85.         
  86.         err = PtrToHand( *drive_icon, &iconHandle, kLargeIconSize );
  87.         forbid( err, PtrToHand );
  88.  
  89.         err = AddIconToSuite(iconHandle, *the_suite, large1BitMask);
  90.     }
  91.     else    // maybe it's a Mac Plus floppy drive; see Tech Note DV 17
  92.     {
  93.         save_resfile = CurResFile();
  94.         UseResFile(0);    // we want a System resource
  95.         err = Get1_resource_icons( the_suite, kFloppyIconResource,
  96.             kSelectorAllAvailableData );
  97.         UseResFile( save_resfile );
  98.     }
  99.  
  100. PtrToHand:
  101. NewIconSuite:
  102. PBHGetVInfoSync:
  103.     return err;
  104. }
  105.